/*
 * @Author: chunlai
 * @Date: 2025-07-17 16:11:22
 * @LastEditTime: 2025-08-07 10:32:33
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \02.bldinsure\src\mixins\bbrsyr.js
 * @Description: 被保人+受益人
 */
import { mapGetters } from "vuex";
export const bbrAndSyrInfoMix = {
  data() {
    return {
      tbrxjAddr: "",
      tbrPostalAddr: "",
    };
  },
  computed: {
    ...mapGetters({
      applicant: "insert/applicant",
      bbrMaxNum: "page/bbrMaxNum",
      bbrMultList: "insert/bbrMultList",
    }),
    tbrWholeAddr() {
      let res = "";
      if (this.tbrxjAddr) {
        res = this.tbrxjAddr;
      } else {
        if (this.applicant.areaName) {
          res += this.applicant.areaName;
        }
        if (this.applicant.permanentAddress) {
          res += this.applicant.permanentAddress;
        }
      }
      return res;
    },
    bbrWholeAddr() {
      let res = "";
      if (this.userInfo.areaName) {
        res += this.userInfo.areaName;
      }
      if (this.userInfo.permanentAddress) {
        res += this.userInfo.permanentAddress;
      }
      return res;
    },
    tbrWholePostAddr() {
      let res = "";
      if (this.tbrPostalAddr) {
        res = this.tbrPostalAddr;
      } else {
        if (this.applicant.postalAreaName) {
          res += this.applicant.postalAreaName;
        }
        if (this.applicant.postalPermanentAddress) {
          res += this.applicant.postalPermanentAddress;
        }
      }
      return res;
    },
    bbrWholePostAddr() {
      let res = "";
      if (this.userInfo.postalAreaName) {
        res += this.userInfo.postalAreaName;
      }
      if (this.userInfo.postalPermanentAddress) {
        res += this.userInfo.postalPermanentAddress;
      }
      return res;
    },
    isSameWithAppnt() {
      let res = false;
      if (this.tbrWholeAddr && this.tbrWholeAddr === this.bbrWholeAddr) {
        res = true;
      }
      return res;
    },
    isSameWithAppntPostalArea() {
      let res = false;
      if (
        this.tbrWholePostAddr &&
        this.tbrWholePostAddr === this.bbrWholePostAddr
      ) {
        res = true;
      }
      return res;
    },
    isSameWithAppntForEmail() {
      let res = false;
      if (
        this.applicant.email &&
        this.userInfo.email === this.applicant.email
      ) {
        res = true;
      }
      return res;
    },
    phoneSameWithAppnt() {
      let res = false;
      if (
        this.applicant.phone &&
        this.userInfo.phone === this.applicant.phone
      ) {
        res = true;
      }
      return res;
    },
    showToInsNo() {
      let res = false;
      if (this.bbrMaxNum > 1) {
        res = true;
      }
      return res;
    },
  },
  methods: {
    sameToAppnt(event, type) {
      if (event) event.preventDefault();
      if (type == "areaName") {
        if (this.applicant.areaName) {
          this.tbrxjAddr = `${this.applicant.areaName}${this.applicant.permanentAddress||''}`;
        } else {
          return;
        }
        this.changeData({
          city: !this.isSameWithAppnt ? this.applicant.city : "",
          cityName: !this.isSameWithAppnt ? this.applicant.cityName : "",
          county: !this.isSameWithAppnt ? this.applicant.county : "",
          countyName: !this.isSameWithAppnt ? this.applicant.countyName : "",
          areaName: !this.isSameWithAppnt ? this.applicant.areaName : "",
          province: !this.isSameWithAppnt ? this.applicant.province : "",
          provinceName: !this.isSameWithAppnt
            ? this.applicant.provinceName
            : "",
          zipCode: !this.isSameWithAppnt ? this.applicant.zipCode : "",
          permanentAddress: !this.isSameWithAppnt
            ? this.applicant.permanentAddress
            : "",
        });
      } else if (type == "postalAreaName") {
        if (
          this.applicant.postalAreaName &&
          this.applicant.postalPermanentAddress
        ) {
          this.tbrPostalAddr = `${this.applicant.postalAreaName}${this.applicant.postalPermanentAddress}`;
        } else {
          return;
        }
        this.changeData({
          postalCity: !this.isSameWithAppntPostalArea
            ? this.applicant.postalCity
            : "",
          postalCityName: !this.isSameWithAppntPostalArea
            ? this.applicant.postalCityName
            : "",
          postalCounty: !this.isSameWithAppntPostalArea
            ? this.applicant.postalCounty
            : "",
          postalCountyName: !this.isSameWithAppntPostalArea
            ? this.applicant.postalCountyName
            : "",
          postalAreaName: !this.isSameWithAppntPostalArea
            ? this.applicant.postalAreaName
            : "",
          postalProvince: !this.isSameWithAppntPostalArea
            ? this.applicant.postalProvince
            : "",
          postalProvinceName: !this.isSameWithAppntPostalArea
            ? this.applicant.postalProvinceName
            : "",
          postalZipCode: !this.isSameWithAppntPostalArea
            ? this.applicant.postalZipCode
            : "",
          postalPermanentAddress: !this.isSameWithAppntPostalArea
            ? this.applicant.postalPermanentAddress
            : "",
        });
      } else if (type == "email") {
        if (!this.applicant.email) return;
        this.changeData({
          email: !this.isSameWithAppntForEmail ? this.applicant.email : "",
        });
      } else if (type == "phone") {
        if (!this.applicant.phone) return;
        this.changeData({
          phone: !this.phoneSameWithAppnt ? this.applicant.phone : "",
        });
      } else if (type == "guardianName") {
        if (!this.applicant.idNum) return;
        this.changeData({
          guardianName: !this.jianhuIsAppnt ? this.applicant.name : "",
          guardianIdNo: !this.jianhuIsAppnt ? this.applicant.idNum : "",
        });
      }
      this.$forceUpdate();
    },
  },
};
